package org.osomit.sacct.security.utils;

import java.security.SecureRandom;

/**
 * A utility class to generate shared security
 *
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jun 26, 2009
 */
public class SharedSecurityGenerator {
	private static int TYPICAL_LENGTH = 20;
	private static int length = TYPICAL_LENGTH;
	private static SecureRandom rand = new SecureRandom();

	public static final int getLength() {
		return length;
	}

	public static void setLength(int length) {
		SharedSecurityGenerator.length = length;
	}

	public static String generateSharedSecret(){
        return generateSharedSecret(TYPICAL_LENGTH);
	}

    public static String generateSharedSecret(int length){
        StringBuffer sb = new StringBuffer(length);
        for(int i=0; i<length; i++)
            sb.append(rand.nextInt(10));

        return sb.toString();
    }

}
